package com.kexio.file.dto;

/**
 * 预览结果
 * 
 * @author kexio
 */
public class PreviewResult {
    
    /** 预览类型 */
    private PreviewType previewType;
    
    /** 预览内容 */
    private String content;
    
    /** 预览内容类型 */
    private String contentType;
    
    /** 预览数据（二进制内容，如图片） */
    private byte[] data;
    
    /** 预览URL */
    private String previewUrl;
    
    /** 文档页数（多页文档） */
    private Integer pageCount;
    
    /** 是否需要转换 */
    private Boolean needConversion;
    
    /** 转换状态 */
    private ConversionStatus conversionStatus;
    
    /** 错误信息 */
    private String errorMessage;

    public enum PreviewType {
        /** 图片直接预览 */
        IMAGE,
        /** HTML预览 */
        HTML,
        /** PDF预览 */
        PDF,
        /** 文本预览 */
        TEXT,
        /** 视频预览 */
        VIDEO,
        /** 音频预览 */
        AUDIO,
        /** 不支持预览 */
        UNSUPPORTED
    }
    
    public enum ConversionStatus {
        /** 不需要转换 */
        NO_CONVERSION,
        /** 转换中 */
        CONVERTING,
        /** 转换完成 */
        CONVERTED,
        /** 转换失败 */
        CONVERSION_FAILED
    }

    // ==================== 构造函数 ====================
    
    public PreviewResult() {}

    public PreviewResult(PreviewType previewType) {
        this.previewType = previewType;
        this.conversionStatus = ConversionStatus.NO_CONVERSION;
    }

    public static PreviewResult unsupported(String errorMessage) {
        PreviewResult result = new PreviewResult(PreviewType.UNSUPPORTED);
        result.setErrorMessage(errorMessage);
        return result;
    }

    public static PreviewResult image(String previewUrl) {
        PreviewResult result = new PreviewResult(PreviewType.IMAGE);
        result.setPreviewUrl(previewUrl);
        return result;
    }

    public static PreviewResult html(String content) {
        PreviewResult result = new PreviewResult(PreviewType.HTML);
        result.setContent(content);
        result.setContentType("text/html");
        return result;
    }

    public static PreviewResult text(String content) {
        PreviewResult result = new PreviewResult(PreviewType.TEXT);
        result.setContent(content);
        result.setContentType("text/plain");
        return result;
    }

    public static PreviewResult pdf(String previewUrl, Integer pageCount) {
        PreviewResult result = new PreviewResult(PreviewType.PDF);
        result.setPreviewUrl(previewUrl);
        result.setPageCount(pageCount);
        return result;
    }

    // ==================== Getter/Setter方法 ====================
    
    public PreviewType getPreviewType() { return previewType; }
    public void setPreviewType(PreviewType previewType) { this.previewType = previewType; }

    public String getContent() { return content; }
    public void setContent(String content) { this.content = content; }

    public String getContentType() { return contentType; }
    public void setContentType(String contentType) { this.contentType = contentType; }

    public byte[] getData() { return data; }
    public void setData(byte[] data) { this.data = data; }

    public String getPreviewUrl() { return previewUrl; }
    public void setPreviewUrl(String previewUrl) { this.previewUrl = previewUrl; }

    public Integer getPageCount() { return pageCount; }
    public void setPageCount(Integer pageCount) { this.pageCount = pageCount; }

    public Boolean getNeedConversion() { return needConversion; }
    public void setNeedConversion(Boolean needConversion) { this.needConversion = needConversion; }

    public ConversionStatus getConversionStatus() { return conversionStatus; }
    public void setConversionStatus(ConversionStatus conversionStatus) { this.conversionStatus = conversionStatus; }

    public String getErrorMessage() { return errorMessage; }
    public void setErrorMessage(String errorMessage) { this.errorMessage = errorMessage; }
}
